package com.sun.umbrella.controller.role;

import com.sun.core.web.result.Result;
import com.sun.umbrella.dao.RoleInfoMapper;
import com.sun.umbrella.domain.bo.RoleInfoBO;
import com.sun.umbrella.domain.query.RoleInfoQuery;
import com.sun.umbrella.domain.vo.ChangeRolePermissionVO;
import com.sun.umbrella.domain.vo.RoleSaveOrUpdateVO;
import com.sun.umbrella.service.bns.role.RoleInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author Jay
 * @version v1.0
 * @description 角色控制器
 * @date 2018-04-09 15:54
 */

@Controller
@Slf4j
@RequestMapping("/pc/role")
public class RoleInfoController {


    @Autowired
    private RoleInfoService roleInfoService;

    @Autowired
    private RoleInfoMapper roleInfoMapper;

    /**
     * 分页查询角色信息
     *
     * @param roleInfoQuery
     * @param pageable
     * @return
     */
    @RequestMapping("/queryRoleInfoList")
    @ResponseBody
    public Result<Page<RoleInfoBO>> queryRoleInfoList(RoleInfoQuery roleInfoQuery
            , @PageableDefault(page = 1, size = 20, sort = "id", direction = Sort.Direction.ASC) Pageable pageable) {
        // 查询
        return Result.wrapSuccessfulResult(roleInfoService.queryRoleInfoList(roleInfoQuery,pageable));
    }


    /**
     * 查询角色列表
     *
     * @param roleInfoQuery
     * @return
     */
    @RequestMapping("/queryRoleList")
    @ResponseBody
    public Result<List<RoleInfoBO>> queryRoleList(RoleInfoQuery roleInfoQuery) {
        // 查询
        return Result.wrapSuccessfulResult(roleInfoMapper.queryRoleInfoList(roleInfoQuery));
    }


    /**
     * 新增角色信息
     *
     * @param roleSaveOrUpdateVO
     * @return
     */
    @RequestMapping("/saveRoleInfo")
    @ResponseBody
    public Result<Boolean> saveRoleInfo(RoleSaveOrUpdateVO roleSaveOrUpdateVO){
        return Result.wrapSuccessfulResult(roleInfoService.saveRoleInfo(roleSaveOrUpdateVO));
    }


    /**
     * 编辑更新角色信息
     *
     * @param roleSaveOrUpdateVO
     * @return
     */
    @RequestMapping("/updateRoleInfo")
    @ResponseBody
    public Result<Boolean> updateRoleInfo(RoleSaveOrUpdateVO roleSaveOrUpdateVO){
        return Result.wrapSuccessfulResult(roleInfoService.updateRoleInfo(roleSaveOrUpdateVO));
    }


    /**
     * 角色 启用或禁用
     *
     * @param roleSaveOrUpdateVO
     * @return
     */
    @RequestMapping("/enableRoleInfo")
    @ResponseBody
    public Result<Boolean> enableRoleInfo(RoleSaveOrUpdateVO roleSaveOrUpdateVO){
        return Result.wrapSuccessfulResult(roleInfoService.enableRoleInfo(roleSaveOrUpdateVO));
    }

    /**
     * 删除角色
     *
     * @param roleSaveOrUpdateVO
     * @return
     */
    @RequestMapping("/deleteRoleInfo")
    @ResponseBody
    public Result<Boolean> deleteRoleInfo(RoleSaveOrUpdateVO roleSaveOrUpdateVO){
        return Result.wrapSuccessfulResult(roleInfoService.deleteRoleInfo(roleSaveOrUpdateVO));
    }


    /**
     * 分配角色权限
     *
     * @param changeRolePermissionVO
     * @return
     */
    @RequestMapping("/changeRolePermission")
    @ResponseBody
    public Result<Boolean> changeRolePermission(ChangeRolePermissionVO changeRolePermissionVO){
        return Result.wrapSuccessfulResult(roleInfoService.changeRolePermission(changeRolePermissionVO));
    }





















}
